package mr.stocks.question1;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import mr.stocks.avro.model.StocksKeyAvro;
import mr.stocks.avro.model.StocksReportAvro;
import mr.stocks.avro.model.StocksValuesAvro;

import org.apache.avro.mapred.AvroKey;
import org.apache.avro.mapred.AvroValue;
import org.apache.avro.mapreduce.AvroMultipleOutputs;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.mapreduce.Reducer;

public class StocksAvroCombiner extends
        Reducer<AvroKey<StocksKeyAvro>, AvroValue<StocksReportAvro>, AvroKey<StocksKeyAvro>, AvroValue<StocksReportAvro>> {
   
	private final StocksReportAvro resultReport = new StocksReportAvro();
    private AvroValue<StocksReportAvro> outputValue = new AvroValue<StocksReportAvro>();
    
    @Override
    protected void reduce(AvroKey<StocksKeyAvro> key, Iterable<AvroValue<StocksReportAvro>> incoming, Context context)
            throws IOException, InterruptedException {
        StocksAvroReducer.collect(key.datum(), resultReport, incoming);
        outputValue.datum(resultReport);
        context.write(key, outputValue);
 
    }
}
